﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BP
{
    public partial class FrmVytvoreniZavodu : System.Windows.Forms.Form
    {
        private string pohlavi = "";
        private short vekOd = 0;
        private short vekDo = 0;

        public FrmVytvoreniZavodu()
        {
            InitializeComponent();
            /* var kateDisciplina = from kd in this.dbConnection.kate_discips
                                  from k in this.dbConnection.kategories
                                  from d in this.dbConnection.disciplinas
                                  where kd.kategorie == k.ID_kat && kd.disciplina == d.ID_Disc
                                  select kd;*/
        }


        private void FrmVytvoreniZavoduLoad(object sender, EventArgs e)
        {
            BpHelper help = new BpHelper();
      //      cb_disciplina.DataSource = help.VypsaniDisciplin();
            cb_soutez.DataSource = BpHelper.VypsaniSoutezi();
        }

        private void BtVytvoritZavodClick(object sender, EventArgs e)
        {


            using (var db = new DbContext())
            {
                
            }
        }

        private void CbDisciplinaSelectedValueChanged(object sender, EventArgs e)
        {
            string i = cb_disciplina.SelectedValue.ToString();
            string[] split = i.Split(new Char[] { '-' });
            //string nazev = Convert.ToString(split[0]);
            var discipliny = from dis in new DbContext().disciplinas
                             where dis.zkratka == split[0].Trim() && dis.pohlavi == split[2].Trim()
                             select dis;
            foreach (var disci in discipliny)
            {
                vekOd = disci.vek_od.Value;
                vekDo = disci.vek_do.Value;
                pohlavi = disci.pohlavi;
            }

            var kategorie = from kat in new DbContext().kategories
                            where kat.pohlavi == pohlavi && kat.vek_od.Value >= vekOd && kat.vek_do.Value <= vekDo
                            select kat;

            var katList = new List<string>();

            foreach (var kat in kategorie)
                katList.Add(kat.nazev);
            cb_kategorieZavod.DataSource = katList;
        }
    }


}
